package{
	import com.pqmvc.PQEvent;
	import com.tools.EventHelper;
	import com.tools.PQDrawTools;
	import com.tools.UIHelper;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	import flashx.textLayout.formats.Float;

	public class AttrView extends Sprite{
		public var boder:Sprite;
		public var curObj:Mc;
		public var left:int=10;
		public var top:int=35;
		public var space:int=5;
		public var txtH:int=20;
		public var lb_name:TextField;
		public var txt_name:TextField;
		public var lb_type:TextField;
		public var txt_type:TextField;
		public var lb_x:TextField;
		public var txt_x:TextField;
		public var lb_y:TextField;
		public var txt_y:TextField;
		public var lb_width:TextField;
		public var txt_width:TextField;
		public var lb_height:TextField;
		public var txt_height:TextField;
		public var lb_scaleX:TextField;
		public var txt_scaleX:TextField;
		public var lb_scaleY:TextField;
		public var txt_scaleY:TextField;
		public var lb_visible:TextField;
		public var txt_visible:TextField;
		public var lb_alpha:TextField;
		public var txt_alpha:TextField;
		public var lb_url:TextField;
		public var txt_url:TextField;
		public var lb_rotation:TextField;
		public var txt_rotation:TextField;
		public var lb_parent:TextField;
		public var txt_parent:TextField;
		public var btn_save:Sprite;
		public function AttrView(){
			super();
			init();
		}
		public function bindData(type:String,obj:Mc):void{
			curObj=obj;
			txt_name.text=obj.name;
			txt_x.text=obj.x.toString();
			txt_y.text=obj.y.toString();
			txt_type.text=obj.type||"img";
			txt_width.text=obj.width.toString();
			txt_height.text=obj.height.toString();
			txt_scaleX.text=obj.scaleX.toString();
			txt_scaleY.text=obj.scaleY.toString();
			txt_visible.text=obj.visible.toString();
			txt_alpha.text=obj.alpha.toString();
			txt_rotation.text=obj.rotation.toString();
			txt_parent.text=obj.parentName;
			txt_url.text=obj.url||"";
		}
		private function save(e:Event):void{
			if(!curObj)return;
			curObj.name=txt_name.text;
			curObj.type=txt_type.text;
			curObj.x=parseInt(txt_x.text);
			curObj.y=parseInt(txt_y.text);
			if(e.target.name=="width"&&curObj.width!=parseInt(txt_width.text)){
				curObj.width=parseInt(txt_width.text);
				txt_scaleX.text=curObj.scaleX.toString();
			}
			if(e.target.name=="height"&&curObj.height!=parseInt(txt_height.text)){
				curObj.height=parseInt(txt_height.text);
				txt_scaleY.text=curObj.scaleY.toString();
			}
			if(e.target.name=="scaleX"&&curObj.scaleX!=parseFloat(txt_scaleX.text)){
				curObj.scaleX=parseFloat(txt_scaleX.text);
				txt_width.text=curObj.width.toString();
			}
			if(e.target.name=="scaleY"&&curObj.scaleY!=parseFloat(txt_scaleY.text)){
				curObj.scaleY=parseFloat(txt_scaleY.text);
				txt_height.text=curObj.height.toString();
			}
			curObj.visible=(txt_visible.text!="false");
			curObj.alpha=parseFloat(txt_alpha.text);
			curObj.rotation=parseFloat(txt_rotation.text);
			curObj.parentName=txt_parent.text;
		}
		private function getFloat(n:Number):Number{
			n=n*100;
			n=Math.round(n);
			return n*0.01;
		}
		private function init():void{
			boder=PQDrawTools.drawRect(0,0,150,600,1,0x000000,0xcccccc);
			addChild(boder);
			lb_name=UIHelper.self.createLabel({text:"属  性",align:"center",bold:1,size:16,x:0,y:10,width:150,height:txtH,parent:this});
			lb_name=UIHelper.self.createLabel({text:"名称:",align:"right",size:12,x:left,y:top,width:50,height:txtH,parent:this});
			txt_name=UIHelper.self.createTxt({text:"",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top,width:50,height:txtH,border:1,parent:this});
			
			lb_type=UIHelper.self.createLabel({text:"类型:",align:"right",size:12,x:left,y:top+txtH+space,width:50,height:txtH,parent:this});
			txt_type=UIHelper.self.createTxt({text:"",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+txtH+space,width:50,height:txtH,border:1,parent:this});
			
			lb_x=UIHelper.self.createLabel({text:"X:",align:"right",size:12,x:left,y:top+(txtH+space)*2,width:50,height:txtH,parent:this});
			txt_x=UIHelper.self.createTxt({text:"",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*2,width:50,height:txtH,border:1,parent:this});
			
			lb_y=UIHelper.self.createLabel({text:"Y:",align:"right",size:12,x:left,y:top+(txtH+space)*3,width:50,height:txtH,parent:this});
			txt_y=UIHelper.self.createTxt({text:"",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*3,width:50,height:txtH,border:1,parent:this});
			
			lb_width=UIHelper.self.createLabel({text:"宽度:",align:"right",size:12,x:left,y:top+(txtH+space)*4,width:50,height:txtH,parent:this});
			txt_width=UIHelper.self.createTxt({text:"",align:"left",name:"width",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*4,width:50,height:txtH,border:1,parent:this});
			
			lb_height=UIHelper.self.createLabel({text:"高度:",align:"right",size:12,x:left,y:top+(txtH+space)*5,width:50,height:txtH,parent:this});
			txt_height=UIHelper.self.createTxt({text:"",align:"left",name:"height",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*5,width:50,height:txtH,border:1,parent:this});
			
			lb_scaleX=UIHelper.self.createLabel({text:"scaleX:",align:"right",size:12,x:left,y:top+(txtH+space)*6,width:50,height:txtH,parent:this});
			txt_scaleX=UIHelper.self.createTxt({text:"1",align:"left",name:"scaleX",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*6,width:50,height:txtH,border:1,parent:this});
			lb_scaleY=UIHelper.self.createLabel({text:"scaleY:",align:"right",size:12,x:left,y:top+(txtH+space)*7,width:50,height:txtH,parent:this});
			txt_scaleY=UIHelper.self.createTxt({text:"1",align:"left",name:"scaleY",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*7,width:50,height:txtH,border:1,parent:this});
			
			lb_rotation=UIHelper.self.createLabel({text:"旋转:",align:"right",size:12,x:left,y:top+(txtH+space)*8,width:50,height:txtH,parent:this});
			txt_rotation=UIHelper.self.createTxt({text:"0",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*8,width:50,height:txtH,border:1,parent:this});
			
			lb_visible=UIHelper.self.createLabel({text:"可见:",align:"right",size:12,x:left,y:top+(txtH+space)*9,width:50,height:txtH,parent:this});
			txt_visible=UIHelper.self.createTxt({text:"true",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*9,width:50,height:txtH,border:1,parent:this});
			
			lb_alpha=UIHelper.self.createLabel({text:"透明度:",align:"right",size:12,x:left,y:top+(txtH+space)*10,width:50,height:txtH,parent:this});
			txt_alpha=UIHelper.self.createTxt({text:"1",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*10,width:50,height:txtH,border:1,parent:this});
			
			lb_parent=UIHelper.self.createLabel({text:"父容器:",align:"right",size:12,x:left,y:top+(txtH+space)*11,width:50,height:txtH,parent:this});
			txt_parent=UIHelper.self.createTxt({text:"1",align:"left",type:TextFieldType.INPUT,size:16,x:left+60,y:top+(txtH+space)*11,width:50,height:txtH,border:1,parent:this});
			
			lb_url=UIHelper.self.createLabel({text:"url:",align:"left",size:12,x:left,y:top+(txtH+space)*12,width:50,height:txtH,parent:this});
			txt_url=UIHelper.self.createTxt({text:"",align:"left",size:12,x:left,y:top+(txtH+space)*13,width:110,height:txtH,border:1,parent:this});
			
			//btn_save=UIHelper.self.createBtn("btn_showAll",this,[PQDrawTools.drawRoundRect(0,0,60,25,1,0x333333,0x339966,1,10),UIHelper.self.createLabel({text:"保 存",width:60,height:25,x:0,y:4,align:"center"})],left*3,top+(txtH+space)*12+30,60,30);
			//btn_save.addEventListener(MouseEvent.CLICK,save);
			
			txt_name.addEventListener(Event.CHANGE,save);
			txt_type.addEventListener(Event.CHANGE,save);
			txt_x.addEventListener(Event.CHANGE,save);
			txt_y.addEventListener(Event.CHANGE,save);
			txt_width.addEventListener(Event.CHANGE,save);
			txt_height.addEventListener(Event.CHANGE,save);
			txt_scaleX.addEventListener(Event.CHANGE,save);
			txt_scaleY.addEventListener(Event.CHANGE,save);
			txt_visible.addEventListener(Event.CHANGE,save);
			txt_alpha.addEventListener(Event.CHANGE,save);
			txt_rotation.addEventListener(Event.CHANGE,save);
			txt_parent.addEventListener(Event.CHANGE,save);
			
			EventHelper.self.addListen(EventType.BIND_MC,bindData);
		}
		public function update():void{
			boder.graphics.clear();
			boder.graphics.beginFill(0xcccccc);
			boder.graphics.drawRect(0,0,150,stage.stageHeight);
			boder.graphics.endFill();
			boder.graphics.lineStyle(1,0x000000);
			boder.graphics.drawRect(0,0,150,stage.stageHeight);
		}
	}
}